#include "../lib/routingindex.hpp"

RoutingIndex::RoutingIndex()
{

}

std::vector <std::string> RoutingIndex::getSubscriber(std::string key)
{
    std::multimap<std::string,std::string>::iterator it,itlow,ithigh;
    std::vector <std::string> ret;
    if(subscriber_.find(key) == subscriber_.end())
        return ret;
    itlow = subscriber_.lower_bound(key);
    ithigh = subscriber_.upper_bound(key);
    for (it=itlow; it!=ithigh; ++it)
        ret.push_back((*it).second);
    return ret;
}

std::vector <std::string> RoutingIndex::getPublisher(std::string key)
{
    std::multimap<std::string,std::string>::iterator it,itlow,ithigh;
    std::vector <std::string> ret;
    if(publisher_.find(key) == publisher_.end())
        return ret;
    itlow = publisher_.lower_bound(key);
    ithigh = publisher_.upper_bound(key);
    for (it=itlow; it!=ithigh; ++it)
        ret.push_back((*it).second);
    return ret;
}

void RoutingIndex::addSubscriber(std::string key, std::string name)
{
    subscriber_.insert(std::make_pair(key,name));
}

void RoutingIndex::addPublisher(std::string key, std::string name)
{
    publisher_.insert(std::make_pair(key,name));
}

void RoutingIndex::clear()
{
    subscriber_.clear();
    publisher_.clear();
}

